package kr.co.mustgo.model.service.membership;

import java.sql.SQLException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import kr.co.mustgo.domain.membership.Membership;
import kr.co.mustgo.membership.exception.DuplicatedIdException;
import kr.co.mustgo.model.dao.membership.MembershipDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

//회원 관리 Business Logic을 처리하는 Business Service 클래스

@Service //name= "MemberServiceImpl" 으로 빈 등록

//start class
public class MembershipServiceImpl implements MembershipService {

		@Autowired //변수에 @Autowired 할 경우 생성자 필요없음(반드시 지워야함?)
		private MembershipDAO dao;
		

//		//생성자
//		public MembershipServiceImpl(MembershipDAO dao){
//			this.dao = dao;
//		}
		
	
		@Override
		public void joinMembership(Membership membership) throws SQLException, DuplicatedIdException{
			//1. 등록된 ID가 있는 지 체크
			//    - 이미 등록된 ID라면 DuplicatedIdException를 발생 시킨다.
		/*	if(dao.selectMembershipById(membership.getId())!=null){
				throw new DuplicatedIdException(membership.getId()+"는 이미 등록된 아이디입니다. ID를 변경하세요");
			}*/
			//2. 디비에 회원정보 등록 처리
			dao.insertMembership(membership);
		}
		//ID로 회원 조회
		@Override
		public Membership getMembershipById(String id) throws SQLException{
			return dao.selectMembershipById(id);
		}
		
		//회원 정보 수정
		@Override
		public void modifyMembership(Membership membership) throws SQLException{
			dao.updateMembership(membership);
		}
		//회원 삭제
		@Override
		public void removeMembershipById(String id) throws SQLException {
			dao.deleteMembershipById(id);
		}
		//전체 회원 목록 조회
		@Override
		public List<Membership> getMembershipList() throws SQLException{
			return dao.selectMembershipList();
		}
		//이름으로 회원 조회
		@Override
		public List<Membership> searchMembershipByName(String name) throws SQLException{
			return  dao.selectMembershipByName(name);
		}
		@Override
		public Map getMembershipListPaging(int page) throws SQLException {
			return null;
		}

	
}//end class
